<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片主体区域 -->
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="Orders.query">
            <el-button slot="append" icon="el-icon-search" @click="Cxun"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 数据表格主体区域 -->

      <el-table :data="OrdersList" border style="width: 100%">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="300"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="180"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template scope="scope">
            <el-tag type="danger" v-if="scope.row.pay_status==0">未付款</el-tag>
            <el-tag type="success" v-if="scope.row.pay_status==1">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="180"></el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="180"></el-table-column>
        <el-table-column prop="name" label="操作" width="180">
          <el-button icon="el-icon-edit" circle type="primary" @click="Xiugai">修改地址</el-button>
          <el-button type="success" icon="el-icon-location-outline" circle @click="Wliuxinxi">查看物流</el-button>
        </el-table-column>
      </el-table>

      <!-- 分页功能 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.Orders.pagenum"
        :page-sizes="[1, 5, 10, 20]"
        :page-size="this.Orders.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.total"
      ></el-pagination>
    </el-card>

    <!-- 修改弹出框 -->
    <el-dialog title="修改地址" :visible.sync="Xiugaidizhi" width="30%">
      省市区/县：
      <!-- 级联选择框 -->
      <el-cascader v-model="jilianList" :options="Citydata" :props="cateProps"></el-cascader>
      <!-- input表单 -->

      <el-form :model="XqingXiugai" :rules="rules" label-width="100px" class="demo-ruleForm">
        <el-form-item label="详细地址" prop="cOrdName">
          <el-input v-model="XqingXiugai.Xqing"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="Xiugaidizhi = false">取 消</el-button>
        <el-button type="primary" @click="Xiugaidizhi = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 物流信息弹出框 -->

    <el-dialog title="物流信息" :visible.sync="dialogVisible1" width="50%">
      <el-timeline reverse>
        <el-timeline-item
          v-for="(item, index) in dataList"
          :key="index"
          :timestamp="item.time"
        >{{item.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
// 导入级联选择框数据
import city from './citydata'

export default {
  data() {
    return {
      // 获取列表参数携带项
      Orders: {
        // 查询参数
        query: '',
        //当前页码
        pagenum: 1,

        //每页显示多少数据
        pagesize: 5
      },

      //   获取列表的所有数据
      OrdersList: [],
      //   数据列表
      or: {
        //订单号:
        order_number: '',
        //   收货人地址
        consignee_addr: '',
        //创建时间
        create_time: '',
        //是否发货
        is_send: '',
        //是否付款
        pay_status: '',
        //订单价格
        order_price: '',
        //订单id
        order_id: ''
      },

      // 获取列表的总条数
      total: 0,
      //修改地址默认为false 隐藏
      Xiugaidizhi: false,
      //   级联选择器数据展示
      cateProps: {
        value: 'value',
        label: 'label',
        children: 'children',
        expandTrigger: 'hover'
      },
      //级联选择器框数据
      jilianList: [],
      //   级联选择框数据源
      Citydata: [],
      //   详细地址输入框填写数据
      XqingXiugai: {
        Xqing: ''
      },

      //   详细地址表单验证
      rules: {
        cOrdName: [
          { required: true, message: '分类名称不能为空', trigger: 'blur' }
        ]
      },
      //物流信息弹出框显示与隐藏
      dialogVisible1: false,

      //   物流信息数据

      dataList: [
        {
          time: '2018-05-10 09:39:00',
          ftime: '2018-05-10 09:39:00',
          context: '已签收,感谢使用顺丰,期待再次为您服务',
          location: ''
        },
        {
          time: '2018-05-10 08:23:00',
          ftime: '2018-05-10 08:23:00',
          context:
            '[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件',
          location: ''
        },
        {
          time: '2018-05-10 07:32:00',
          ftime: '2018-05-10 07:32:00',
          context: '快件到达 [北京海淀育新小区营业点]',
          location: ''
        },
        {
          time: '2018-05-10 02:03:00',
          ftime: '2018-05-10 02:03:00',
          context:
            '快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]',
          location: ''
        },
        {
          time: '2018-05-09 23:05:00',
          ftime: '2018-05-09 23:05:00',
          context: '快件到达 [北京顺义集散中心]',
          location: ''
        },
        {
          time: '2018-05-09 21:21:00',
          ftime: '2018-05-09 21:21:00',
          context: '快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]',
          location: ''
        },
        {
          time: '2018-05-09 13:07:00',
          ftime: '2018-05-09 13:07:00',
          context: '顺丰速运 已收取快件',
          location: ''
        },
        {
          time: '2018-05-09 12:25:03',
          ftime: '2018-05-09 12:25:03',
          context: '卖家发货',
          location: ''
        },
        {
          time: '2018-05-09 12:22:24',
          ftime: '2018-05-09 12:22:24',
          context: '您的订单将由HLA（北京海淀区清河中街店）门店安排发货。',
          location: ''
        },
        {
          time: '2018-05-08 21:36:04',
          ftime: '2018-05-08 21:36:04',
          context: '商品已经下单',
          location: ''
        }
      ],
      meta: { status: 200, message: '获取物流信息成功！' }
    }
  },
  created() {
    this.getOrders()
    console.log(this.dataList)

    this.Citydata = city
  },
  methods: {
    //   获取订单数据列表
    async getOrders() {
      const { data: res } = await this.$http.get('orders', {
        params: this.Orders
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表数据失败')
      }
      this.$message.success('获取订单列表成功')
      this.OrdersList = res.data.goods
      this.total = res.data.total
      console.log(res)
    },
    // 分页pagesize改变时触发
    handleSizeChange(newpageSize) {
      //   console.log(newpageSize)
      //   console.log(111)

      this.Orders.pagesize = newpageSize
      this.getOrders()
    },
    // 分页currentPage改变时会触发
    handleCurrentChange(newcurrentPage) {
      //   console.log(newcurrentPage)

      this.Orders.pagenum = newcurrentPage
      this.getOrders()
      //   console.log(this.Orders.pagenum)
    },
    // 点击查询时调用参数
    async Cxun() {
      const { data: res } = await this.$http.get('orders', {
        params: this.Orders
      })
      console.log(res)

      if (res.meta.status !== 200) {
        return this.$message.error('查询订单列表数据失败')
      }
      this.$message.success('查询订单列表成功')
      this.getOrders()
      console.log(this.Orders)
    },
    // 点击修改调用
    Xiugai() {
      this.Xiugaidizhi = true
      console.log()
    },
    //点击查看按钮调用
    Wliuxinxi() {
      this.dialogVisible1 = true
    }
  }
}
</script>

<style lang="less" scoped>
</style>